package controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.KeyStroke;

/**
 * Configures the Keys.
 *
 * @author joseph
 */
public class KeyConfig {
    private File config;
    private File default_keys;
    public KeyStroke keys[];
    public KeyConfig(){
        keys = new KeyStroke[43];
        config = new File("keys.spiceconfig");
        default_keys = new File("default.spiceconfig");
        loadDefault();
        if(keys[0] == null){load();}
    }
    public KeyStroke getCursorSouthWest(){ return keys[0]; }
    public KeyStroke getCursorSouth(){ return keys[1]; }
    public KeyStroke getCursorSouthEast(){ return keys[2]; }
    public KeyStroke getCursorCenter(){ return keys[3]; }
    public KeyStroke getCursorNorthWest(){ return keys[4]; }
    public KeyStroke getCursorNorth(){ return keys[5]; }
    public KeyStroke getCursorNorthEast(){ return keys[6]; }
    public KeyStroke getCycleTypeDown(){ return keys[7]; }
    public KeyStroke getCycleTypeUp(){ return keys[8]; }
    public KeyStroke getCycleSubtypeDown(){ return keys[9]; }
    public KeyStroke getCycleSubtypeUp(){ return keys[10]; }
    public KeyStroke getCycleCommandDown(){ return keys[11]; }
    public KeyStroke getCycleCommandUp(){ return keys[12]; }
    public KeyStroke getCycleInstanceDown(){ return keys[13]; }
    public KeyStroke getCycleInstanceUp(){ return keys[14]; }
    public KeyStroke getDirectionSouthWest(){ return keys[15]; }
    public KeyStroke getDirectionSouth(){ return keys[16]; }
    public KeyStroke getDirectionSouthEast(){ return keys[17]; }
    public KeyStroke getDirectionCenter(){ return keys[18]; }
    public KeyStroke getDirectionNorthWest(){ return keys[19]; }
    public KeyStroke getDirectionNorth(){ return keys[20]; }
    public KeyStroke getDirectionNorthEast(){ return keys[21]; }
    public KeyStroke getEnter(){ return keys[22]; }
    public KeyStroke get0(){ return keys[23]; }
    public KeyStroke get1(){ return keys[24]; }
    public KeyStroke get2(){ return keys[25]; }
    public KeyStroke get3(){ return keys[26]; }
    public KeyStroke get4(){ return keys[27]; }
    public KeyStroke get5(){ return keys[28]; }
    public KeyStroke get6(){ return keys[29]; }
    public KeyStroke get7(){ return keys[30]; }
    public KeyStroke get8(){ return keys[31]; }
    public KeyStroke get9(){ return keys[32]; }
    public KeyStroke getSelection0(){ return keys[33]; }
    public KeyStroke getSelection1(){ return keys[34]; }
    public KeyStroke getSelection2(){ return keys[35]; }
    public KeyStroke getSelection3(){ return keys[36]; }
    public KeyStroke getSelection4(){ return keys[37]; }
    public KeyStroke getSelection5(){ return keys[38]; }
    public KeyStroke getSelection6(){ return keys[39]; }
    public KeyStroke getSelection7(){ return keys[40]; }
    public KeyStroke getSelection8(){ return keys[41]; }
    public KeyStroke getSelection9(){ return keys[42]; }
    public void load(){
        try{
            FileInputStream in = new FileInputStream(config);
            ObjectInputStream fromFile = new ObjectInputStream(in);
            keys = (KeyStroke[])fromFile.readObject();
        }catch(Exception ex){}
    }
    public void loadDefault(){
        try{
            FileInputStream in = new FileInputStream(default_keys);
            ObjectInputStream fromFile = new ObjectInputStream(in);
            keys = (KeyStroke[])fromFile.readObject();
        }catch(Exception ex){}
    }
    public void save(){
        try {
            FileOutputStream out = new FileOutputStream(config);
            ObjectOutputStream toFile = new ObjectOutputStream(out);
            toFile.writeObject(keys);
            System.out.println("No Save Error");
        } catch (Exception ex){System.out.println(ex);}
    }
    public void setCursorSouthWest(KeyStroke key){ keys[0] = key; }
    public void setCursorSouth(KeyStroke key){ keys[1] = key; }
    public void setCursorSouthEast(KeyStroke key){ keys[2] = key; }
    public void setCursorCenter(KeyStroke key){ keys[3] = key; }
    public void setCursorNorthWest(KeyStroke key){ keys[4] = key; }
    public void setCursorNorth(KeyStroke key){ keys[5] = key; }
    public void setCursorNorthEast(KeyStroke key){ keys[6] = key; }
    public void setCycleTypeDown(KeyStroke key){ keys[7] = key; }
    public void setCycleTypeUp(KeyStroke key){ keys[8] = key; }
    public void setCycleSubtypeDown(KeyStroke key){ keys[9] = key; }
    public void setCycleSubtypeUp(KeyStroke key){ keys[10] = key; }
    public void setCycleCommandDown(KeyStroke key){ keys[11] = key; }
    public void setCycleCommandUp(KeyStroke key){ keys[12] = key; }
    public void setCycleInstanceDown(KeyStroke key){ keys[13] = key; }
    public void setCycleInstanceUp(KeyStroke key){ keys[14] = key; }
    public void setDirectionSouthWest(KeyStroke key){ keys[15] = key; }
    public void setDirectionSouth(KeyStroke key){ keys[16] = key; }
    public void setDirectionSouthEast(KeyStroke key){ keys[17] = key; }
    public void setDirectionCenter(KeyStroke key){ keys[18] = key; }
    public void setDirectionNorthWest(KeyStroke key){ keys[19] = key; }
    public void setDirectionNorth(KeyStroke key){ keys[20] = key; }
    public void setDirectionNorthEast(KeyStroke key){ keys[21] = key; }
    public void setEnter(KeyStroke key){ keys[22] = key; }
    public void set0(KeyStroke key){ keys[23] = key; }
    public void set1(KeyStroke key){ keys[24] = key; }
    public void set2(KeyStroke key){ keys[25] = key; }
    public void set3(KeyStroke key){ keys[26] = key; }
    public void set4(KeyStroke key){ keys[27] = key; }
    public void set5(KeyStroke key){ keys[28] = key; }
    public void set6(KeyStroke key){ keys[29] = key; }
    public void set7(KeyStroke key){ keys[30] = key; }
    public void set8(KeyStroke key){ keys[31] = key; }
    public void set9(KeyStroke key){ keys[32] = key; }
    public void setSelection0(KeyStroke key){ keys[33] = key; }
    public void setSelection1(KeyStroke key){ keys[34] = key; }
    public void setSelection2(KeyStroke key){ keys[35] = key; }
    public void setSelection3(KeyStroke key){ keys[36] = key; }
    public void setSelection4(KeyStroke key){ keys[37] = key; }
    public void setSelection5(KeyStroke key){ keys[38] = key; }
    public void setSelection6(KeyStroke key){ keys[39] = key; }
    public void setSelection7(KeyStroke key){ keys[40] = key; }
    public void setSelection8(KeyStroke key){ keys[41] = key; }
    public void setSelection9(KeyStroke key){ keys[42] = key; }

    public static void main(String args[]){
        KeyConfig conf = new KeyConfig();
        conf.set0(KeyStroke.getKeyStroke(48,0));
        conf.set1(KeyStroke.getKeyStroke(49,0));
        conf.set2(KeyStroke.getKeyStroke(50,0));
        conf.set3(KeyStroke.getKeyStroke(51,0));
        conf.set4(KeyStroke.getKeyStroke(52,0));
        conf.set5(KeyStroke.getKeyStroke(53,0));
        conf.set6(KeyStroke.getKeyStroke(54,0));
        conf.set7(KeyStroke.getKeyStroke(55,0));
        conf.set8(KeyStroke.getKeyStroke(56,0));
        conf.set9(KeyStroke.getKeyStroke(57,0));
        conf.setSelection0(KeyStroke.getKeyStroke(48,0));
        conf.setSelection1(KeyStroke.getKeyStroke(49,0));
        conf.setSelection2(KeyStroke.getKeyStroke(50,0));
        conf.setSelection3(KeyStroke.getKeyStroke(51,0));
        conf.setSelection4(KeyStroke.getKeyStroke(52,0));
        conf.setSelection5(KeyStroke.getKeyStroke(53,0));
        conf.setSelection6(KeyStroke.getKeyStroke(54,0));
        conf.setSelection7(KeyStroke.getKeyStroke(55,0));
        conf.setSelection8(KeyStroke.getKeyStroke(56,0));
        conf.setSelection9(KeyStroke.getKeyStroke(57,0));
        conf.setEnter(KeyStroke.getKeyStroke(10,0));
        conf.setCursorSouthWest(KeyStroke.getKeyStroke(97,0));
        conf.setCursorSouth(KeyStroke.getKeyStroke(98,0));
        conf.setCursorSouthEast(KeyStroke.getKeyStroke(99,0));
        conf.setCursorCenter(KeyStroke.getKeyStroke(101,0));
        conf.setCursorNorthWest(KeyStroke.getKeyStroke(103,0));
        conf.setCursorNorth(KeyStroke.getKeyStroke(104,0));
        conf.setCursorNorthEast(KeyStroke.getKeyStroke(105,0));
        conf.setCycleTypeDown(KeyStroke.getKeyStroke(38,2));
        conf.setCycleTypeUp(KeyStroke.getKeyStroke(40,2));
        conf.setCycleSubtypeUp(KeyStroke.getKeyStroke(37,2));
        conf.setCycleSubtypeDown(KeyStroke.getKeyStroke(39,2));
        conf.setCycleCommandDown(KeyStroke.getKeyStroke(38,0));
        conf.setCycleCommandUp(KeyStroke.getKeyStroke(40,0));
        conf.setCycleInstanceUp(KeyStroke.getKeyStroke(37,0));
        conf.setCycleInstanceDown(KeyStroke.getKeyStroke(39,0));
        conf.setDirectionSouthWest(KeyStroke.getKeyStroke(97,0));
        conf.setDirectionSouth(KeyStroke.getKeyStroke(98,0));
        conf.setDirectionSouthEast(KeyStroke.getKeyStroke(99,0));
        conf.setDirectionCenter(KeyStroke.getKeyStroke(101,0));
        conf.setDirectionNorthWest(KeyStroke.getKeyStroke(103,0));
        conf.setDirectionNorth(KeyStroke.getKeyStroke(104,0));
        conf.setDirectionNorthEast(KeyStroke.getKeyStroke(105,0));
        System.out.println("Key:");
        for(int i = 0; i < 43; i++){
            System.out.println(conf.keys[i].toString());
        }
        conf.save();

    }
}